package com.parachutes.aspsystemweb.config;



import com.parachutes.aspsystemapi.domian.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 全局异常配置
 *
 * @author machi
 * @date 2022/05/29
 */
@ControllerAdvice
public class GlobalExceptionConfig {
    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionConfig.class);

//    @ExceptionHandler(value = UnauthenticatedException.class)
//    @ResponseBody
//    public Result handle(UnauthenticatedException e) {
//        e.printStackTrace();
//        return Result.of(false, "未登录，请先登录!");
//    }
//
//    /**
//     * shiro 未授权异常
//     */
//    @ExceptionHandler(value = AuthorizationException.class)
//    @ResponseBody
//    public Result handle(AuthorizationException e) {
//        e.printStackTrace();
//        return Result.of(false, "无权限操作");
//    }
    /**
     * shiro 未授权异常
     */
    @ExceptionHandler(value = MethodArgumentNotValidException.class)
    @ResponseBody
    public Result<?> handle(MethodArgumentNotValidException e) {
        log.error("系统错误",e);
        return Result.of(false, e.getMessage());
    }
    /**
     * shiro 未授权异常
     */
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result<?> handle(Exception e) {
        log.error("系统错误",e);
        return Result.of(false, e.getMessage());
    }



}
